﻿using sentrygrpc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sentryctl
{
    public static class Writer
    {
        public static void Write(string value)
        {
            //Console.ForegroundColor = ConsoleColor.Blue;
            Console.Write(value);
            //Console.ForegroundColor = ConsoleColor.White;
        }

        public static void WriteEnter()
        {
            Console.Write("\r\n");
        }

        public static void WriteTab()
        {
            Console.Write("\t");
        }

        public static void WriteSpace()
        {
            Console.Write(" ");
        }

        public static void WriteLine(string value)
        {
            //Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine(value);
            //Console.ForegroundColor = ConsoleColor.White;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="status"></param>
        /// <param name="pid"></param>
        /// <param name="uptime"></param>
        public static void WriteStatus(string name,StatusType type,string pid,string uptime)
        {
            Write(name);
            Format(name, 30);

            string stype = "stop";
            switch (type)
            {
                case StatusType.Running:
                    stype = "running";
                    break;
                case StatusType.Stop:
                    stype = "stop";
                    break;
            }

            if (type == StatusType.Running)
            {
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.Write(stype);
                Console.BackgroundColor = ConsoleColor.Black;
                Format(stype, 10);
                Write("pid ");
                Write(pid);
                Format(pid, 10);
                Write("uptime ");
                Write(uptime);
            }
            else
            {
                Write(stype);
            }
        }

        private static void Format(string value,int allLength)
        {
            int length = allLength - value.Length;
            if (length > 0)
            {
                for (int i = 0; i < length; i++)
                {
                    WriteSpace();
                }
            }
        }
    }
}

